# Contributor: Holger Jaekel <holger.jaekel@gmx.de>
# Maintainer: Holger Jaekel <holger.jaekel@gmx.de>
pkgname=mdbtools
pkgver=1.0.0
pkgrel=1
pkgdesc="library for reading MS Access database files"
url="https://github.com/mdbtools/mdbtools"
arch="all !s390x"  # no support for big-endian
license="GPL-2.0-or-later"
makedepends="
	autoconf
	automake
	bison
	flex
	gawk
	gettext-dev
	gnu-libiconv-dev
	libtool
	unixodbc-dev
	"
subpackages="
	$pkgname-dev
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-utils
	$pkgname-odbc
	"
_testdata=e649f792cb8f966d404e052d1523e93de0192d50
source="
	https://github.com/mdbtools/mdbtools/releases/download/v$pkgver/mdbtools-$pkgver.tar.gz
	mdbtestdata-$_testdata.tar.gz::https://github.com/mdbtools/mdbtestdata/archive/$_testdata.tar.gz
	10-Werror.patch
	"

prepare() {
	default_prepare

	mv "$srcdir"/mdbtestdata-$_testdata "$builddir"/test

	autoreconf -i -f
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--enable-static=no \
		--with-unixodbc=/usr/include \
		--with-libiconv-prefix=/usr/include
	make
}

check() {
	# taken from https://github.com/mdbtools/mdbtools/blob/master/test_script.sh
	./src/util/mdb-json test/data/ASampleDatabase.accdb "Asset Items"
	./src/util/mdb-json test/data/nwind.mdb "Umsätze"
	./src/util/mdb-count test/data/ASampleDatabase.accdb "Asset Items"
	./src/util/mdb-count test/data/nwind.mdb "Umsätze"
	./src/util/mdb-prop test/data/ASampleDatabase.accdb "Asset Items"
	./src/util/mdb-prop test/data/nwind.mdb "Umsätze"
	./src/util/mdb-schema test/data/ASampleDatabase.accdb
	./src/util/mdb-schema test/data/nwind.mdb
	./src/util/mdb-schema test/data/nwind.mdb -T "Umsätze" postgres
	./src/util/mdb-tables test/data/ASampleDatabase.accdb
	./src/util/mdb-tables test/data/nwind.mdb
	./src/util/mdb-ver test/data/ASampleDatabase.accdb
	./src/util/mdb-ver test/data/nwind.mdb
	./src/util/mdb-queries test/data/ASampleDatabase.accdb qryCostsSummedByOwner
}

package() {
	make DESTDIR="$pkgdir" install
}

utils() {
	pkgdesc="library for reading MS Access database files (command line utilities)"
	amove /usr/bin
}

odbc() {
	pkgdesc="library for reading MS Access database files (ODBC driver for use with unixODBC)"
	amove /usr/lib/odbc/libmdbodbc*
}

sha512sums="
146606d1c26c939cef5d4e153f312c24858e0a2eeaad9260c3bdd5eea9f5b58f5fd06ccad72323aa18db5fe197b4c50167b3ca9e112f1a8200ea5b69e1b16ccd  mdbtools-1.0.0.tar.gz
e7bee8761ff20e231ccf50fe5b4eb917c774a8c60fab4769f39bac024c5a507537db407ac616930203222e5965e0a7556a87d39555e3c4e2a543f6a49e890aea  mdbtestdata-e649f792cb8f966d404e052d1523e93de0192d50.tar.gz
c3ab42c277546d74760be28592ec4a15194c0df837f3043b3d66918658c35100def729b50222e9f3f9f301a2c49a6aeb6b7b810afbacc9f636f12934aa1a3cb9  10-Werror.patch
"
